package com.gouaixin.bee.beeframework2.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.widget.ImageView;

import com.gouaixin.bee.beeframework2.R;
//import com.gouaixin.bee.beeframework2.model.SmsModel;
import com.gouaixin.bee.beeframework2.component.DragImageView;

import java.io.InputStream;


public class showPhotoActivity extends Activity {
    private int window_width, window_height;// 控件宽度
    private DragImageView dragImageView;// 自定义控件
    private int state_height;// 状态栏的高度

    private ViewTreeObserver viewTreeObserver;

    private ImageView showTv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.showphoto);

        showTv= (ImageView) findViewById(R.id.showTv);

        Intent intent=getIntent();
        if(intent!=null)
        {
             Bitmap bitmap=intent.getParcelableExtra("bitmap");

            // 设置图片
            showTv.setImageBitmap(bitmap);
        }




//        /** 获取可見区域高度 **/
//        WindowManager manager = getWindowManager();
//        window_width = manager.getDefaultDisplay().getWidth();
//        window_height = manager.getDefaultDisplay().getHeight();
//
//        dragImageView = (DragImageView) findViewById(R.id.div_main);
//
//
//        Intent intent=getIntent();
//        if(intent!=null)
//        {
//             Bitmap bitmap=intent.getParcelableExtra("bitmap");
//
//            // 设置图片
//            dragImageView.setImageBitmap(bitmap);
//            dragImageView.setmActivity(this);//注入Activity.
//        }
////        Bitmap bmp = BitmapUtil.ReadBitmapById(this, R.drawable.huoying,
////                window_width, window_height);
//
//        /** 测量状态栏高度 **/
//        viewTreeObserver = dragImageView.getViewTreeObserver();
//        viewTreeObserver
//                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
//
//                    @Override
//                    public void onGlobalLayout() {
//                        if (state_height == 0) {
//                            // 获取状况栏高度
//                            Rect frame = new Rect();
//                            getWindow().getDecorView()
//                                    .getWindowVisibleDisplayFrame(frame);
//                            state_height = frame.top;
//                            dragImageView.setScreen_H(window_height-state_height);
//                            dragImageView.setScreen_W(window_width);
//                        }
//
//                    }
//                });

    }

    /**
     * 读取本地资源的图片
     *
     * @param context
     * @param resId
     * @return
     */
    public static Bitmap ReadBitmapById(Context context, int resId) {
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inPreferredConfig = Bitmap.Config.RGB_565;
        opt.inPurgeable = true;
        opt.inInputShareable = true;
        // 获取资源图片
        InputStream is = context.getResources().openRawResource(resId);
        return BitmapFactory.decodeStream(is, null, opt);
    }

}